import sqlite3


def printGoogle(placesDB):
    try:
        conn = sqlite3.connect(placesDB)
        c = conn.cursor()
        # 使用三引号来包含整个 SQL 查询，并修正字段名（应该是 'url' 而不是 'ur1'）
        c.execute("""  
            SELECT url, datetime(visit_date/1000000, 'unixepoch') AS visit_date  
            FROM moz_places  
            JOIN moz_historyvisits ON moz_places.id = moz_historyvisits.place_id  
            WHERE visit_count > 0;  
        """)
        print('\n[*] -- Found Google History --')
        for row in c.fetchall():
            url = row[0]
            date = row[1]
            # 检查 URL 是否包含 'google'（不区分大小写）
            if 'google' in url.lower():
                print(f'[+] Visited Google URL: {url} on {date}')
    except Exception as e:
        # 改进错误消息，明确指出可能是数据库路径问题或加密问题
        if 'encrypted' in str(e):
            print('\n[*] Error reading your places database. The database may be encrypted.')
            print('[*] Ensure your database path is correct and you have the necessary decryption tools.')
        else:
            # 对于其他类型的错误，打印出具体的错误信息
            print(f'\n[*] An error occurred: {e}')
            print('[*] Check your database path and permissions.')
    finally:
        # 无论是否发生异常，都关闭数据库连接
        conn.close()

    # 调用函数，确保文件路径正确


printGoogle(r"C:\Users\yangchen\AppData\Roaming\Mozilla\Firefox\Profiles\lkcrh8j5.default-release\places.sqlite")